package com.ruoyi.parkingcar.controller;


import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.parkingcar.domain.ParkCar;
import com.ruoyi.parkingcar.service.ParkCarService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/parkingcar/Car")
public class ParkCarController {

   @Autowired
   private ParkCarService parkCarService;

   //增加
    @PostMapping("/addCar")
    public AjaxResult addCar(@RequestBody ParkCar parkCar) {
        int registerResult = parkCarService.insertParkCar(parkCar);
        if (registerResult  != 0) {
            return AjaxResult.success("增加成功").put("data",parkCar);

        } else {
            return AjaxResult.error("增加失败，请检查输入信息");
        }
    }

    @GetMapping("/allCar")
    public AjaxResult allCar(String licensePlate) {
        ParkCar car = parkCarService.selectParkCar(licensePlate);
        return AjaxResult.success("查询成功").put("data",car);

    }


    /**
     *
     *Vant端口i添加车牌
     */

    @PostMapping("/AddLicensePlate")
    public AjaxResult addLicensePlate(@RequestBody ParkCar parkCar) {
        int registerResult = parkCarService.AddLicensePlate(parkCar);
        if (registerResult  != 0) {
            return AjaxResult.success("增加成功").put("data",parkCar);
        }else{
            return AjaxResult.error("增加失败，请检查输入信息");
        }
    }

    @GetMapping("/CarByAcc")
        public AjaxResult CarByAcc(ParkCar parkCar) {
        List<ParkCar> car = parkCarService.CarByAcc(parkCar);
           return AjaxResult.success("查询成功").put("data",car);
        }


    @PostMapping("/delete")
    public AjaxResult delete(@RequestBody ParkCar parkCar) {
        int delete = parkCarService.deleteCar(parkCar);
        if (delete != 0) {
            return AjaxResult.success("删除成功").put("data",parkCar);
        }else {
            return AjaxResult.error("删除失败");
        }
    }

    @PostMapping("/update")
    public AjaxResult update(@RequestBody ParkCar parkCar) {
        int update = parkCarService.updateCar(parkCar);
        if (update != 0) {
            return AjaxResult.success("修改成功").put("data", parkCar);
        } else {
            return AjaxResult.error("修改失败").put("data", null);
        }
    }
}
